package com.fast.common.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ErrorMsg {

	private static Logger logger = LoggerFactory.getLogger(ErrorMsg.class);

	private static Properties prop = null;

	static {
		InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/message.properties");
		try {
			prop = new Properties();
			if( is != null ){
				InputStreamReader reader = new InputStreamReader(is, "UTF-8");
				prop.load(reader);
			}
		} catch (UnsupportedEncodingException e) {
			logger.error("加载配置文件错误==>", e);
		} catch (IOException e) {
			logger.error("加载配置文件错误==>", e);
		}
	}

	public static String getMsg(String code) {
		try{
			return prop.getProperty(code);
		}catch( Exception e ){
			logger.error("", e);
		}
		return null;
	}
	
	public static String getMsg(String code , String defaultVal ) {
		String msg = prop.getProperty(code);
		if( StringUtils.isEmpty(msg)){
			return defaultVal;
		}
		return msg;
	}
	
	
}
